package com.example.gzysmartcity.ui.adapter;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.gzysmartcity.R;
import com.example.gzysmartcity.repository.model.News;

import org.jetbrains.annotations.NotNull;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class NewsAdapter extends BaseQuickAdapter<News, BaseViewHolder> {
    public NewsAdapter(int layoutResId) {
        super(layoutResId);
        simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd kk:mm", Locale.CHINA);
    }

    private final SimpleDateFormat simpleDateFormat;

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, News news) {
        ImageView imageView = baseViewHolder.getView(R.id.imgRvItemNews);
        Glide.with(getContext()).load(news.getImgUrl()).placeholder(R.drawable.error).into(imageView);
        baseViewHolder.setText(R.id.tvRvItemNewsTitle, news.getTitle());
        baseViewHolder.setText(R.id.tvRvItemNewsContent, news.getContent());
        baseViewHolder.setText(R.id.tvRvItemNewsName, news.getAuthor());
        baseViewHolder.setText(R.id.tvRvItemNewsDate, simpleDateFormat.format(new Date((long) news.getTime() * 1000)));

    }
}
